description "Docker daemon"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]
limit nofile 524288 1048576
limit nproc 524288 1048576

respawn

kill timeout 20

pre-start script
    # see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
    if grep -v '^#' /etc/fstab | grep -q cgroup \
        || [ ! -e /proc/cgroups ] \
        || [ ! -d /sys/fs/cgroup ]; then
        exit 0
    fi
    if ! mountpoint -q /sys/fs/cgroup; then
        mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
    fi
    (
        cd /sys/fs/cgroup
        for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
            mkdir -p $sys
            if ! mountpoint -q $sys; then
                if ! mount -n -t cgroup -o $sys cgroup $sys; then
                    rmdir $sys || true
                fi
            fi
        done
    )
end script

script
    # modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
    if [ -f /etc/default/$UPSTART_JOB ]; then
        . /etc/default/$UPSTART_JOB
    fi
    exec <%= @docker_daemon_cmd %> <%= @docker_raw_logs_arg %>
end script

post-start script
  <%= @docker_wait_ready %>
  if [ $? -eq 0 ]; then
    echo "<%= @docker_socket %> is up"
  else
    echo "<%= @docker_socket %> failed to start"
    exit 1
  fi
end script
